perl comparing 2 data file as array 2D for finding match one to one [migrated]

Posted by roman serpa on Programmers See other posts from Programmers or by roman serpa
Published on 2013-10-21T22:12:14Z Indexed on 2013/10/22 4:06 UTC
Read the original article Hit count: 359

Filed under:
|

I'm doing a program that uses combinations of variables ( combiData.txt 63 rows x different number of columns) for analysing a data table ( j1j2_1.csv, 1000filas x 19 columns ) , to choose how many times each combination is repeated in data table and which rows come from (for instance, tableData[row][4]).

I have tried to compile it , however I get the following message :

Use of uninitialized value $val in numeric eq (==) at rowInData.pl line 34. Use of reference "ARRAY(0x1a2eae4)" as array index at rowInData.pl line 56. Use of reference "ARRAY(0x1a1334c)" as array index at rowInData.pl line 56. Use of uninitialized value in subtraction (-) at rowInData.pl line 56. Modification of non-creatable array value attempted, subscript -1 at rowInData.pl line 56. nothing


      This is my code:

      #!/usr/bin/perl
      use strict;
      use warnings;

      my $line_match;
      my $countTrue;

       open (FILE1, "<combiData.txt") or die "can't open file text1.txt\n";
       my @tableCombi;
       while(<FILE1>) {
       my @row = split(' ', $_);
       push(@tableCombi, \@row);
       }
       close FILE1 || die $!;

       open (FILE2, "<j1j2_1.csv") or die "can't open file text1.txt\n";
       my @tableData;
       while(<FILE2>) {
          my @row2 = split(/\s*,\s*/, $_);
       push(@tableData, \@row2);
       }
       close FILE2 || die $!;

      #function transform combiData.txt variable (position ) to the real value that i have to  find in the data table.
      sub trueVal($){
      my ($val) = $_[0];
      if($val == 7){ return ('nonsynonymous_SNV'); }
      elsif( $val == 14)          { return '1'; }
      elsif( $val == 15)   { return '1';}
      elsif( $val == 16)    { return '1'; }
      elsif( $val == 17)        { return '1'; }
      elsif( $val == 18)      { return '1';}
      elsif( $val == 19)     { return '1';}
      else              { print 'nothing'; }
      }

     #function  IntToStr ( ) , i'm not sure if it is necessary) that transforms $ to strings  ,     to use the function <eq> in the third loop for the array of combinations compared with the data  array .
     sub IntToStr { return "$_[0]"; } 



     for my $combi (@tableCombi) {
     $line_match = 0;

         for my $sheetData (@tableData) {
        $countTrue=0;

       for my $cell ( @$combi) {
             #my $temp =\$tableCombi[$combi][$cell] ;
         #if ( trueVal($tableCombi[$combi][$cell] )  eq $tableData[$sheetData][ $tableCombi[$combi][$cell] - 1 ]   ){
         #if ( IntToStr(trueVal($$temp )) eq IntToStr( $tableData[$sheetData][ $$temp-1] ) ){
         if ( IntToStr(trueVal($tableCombi[$combi][$cell]) )  eq IntToStr($tableData[$sheetData][ $tableCombi[$combi][$cell] -1])  ){
            $countTrue++;}
         if ($countTrue==@$combi){
            $line_match++;
            #if ($line_match < 50){
            print $tableData[$sheetData][4]." ";
            #}
         }  

     }
  }
print $line_match." \n";
 }

© Programmers or respective owner

Related posts about perl

Related posts about array